import { Component, OnInit } from '@angular/core';
import {NbDialogService, NbToastrService} from '@nebular/theme';
import {NbToastStatus} from '@nebular/theme/components/toastr/model';
import {ButtonViewComponent} from '../food/food.component';
import {LocalDataSource} from 'ng2-smart-table';
import {HttpClient} from '@angular/common/http';
import {ReturnData} from '../../login/login.component';
import {SERVER_URL} from '../../config';
import {FoodService} from '../../service/food.service';

@Component({
  selector: 'app-produce-find',
  templateUrl: './produce-find.component.html',
  styleUrls: ['./produce-find.component.css']
})
export class ProduceFindComponent implements OnInit {

  source: LocalDataSource = new LocalDataSource();
  public produceInfo: any = [];

  constructor(private foodService: FoodService,
              private http: HttpClient,
              private dialogService: NbDialogService,
              private toastrService: NbToastrService) {
    this.loadData();
  }

  settings = {
    noDataMessage: '暂无数据',
    actions: {
      add: false,
      edit: false,
      delete: false,
      columnTitle: '审批',
    },
    columns: {
      id: {
        title: 'ID',
        type: 'number',
        editable: false,
      },
      Batch: {
        title: '批次',
        type: 'string',
      },
      FoodName: {
        title: '食品名称',
        type: 'string',
      },
      Produce_date: {
        title: '生产日期',
        type: 'string',
      },
      qty: {
        title: '数量',
        type: 'string',
      },
      CompanyName: {
        title: '公司名称',
        type: 'string',
      },

    },
  };

  async loadData() {
    const formData = new FormData();
    this.produceInfo = await this.foodService.getAll('?s=App.Manualready.Selectall', formData);
    console.log(this.produceInfo);
    this.source.load(this.produceInfo.data.code);
  }

  ngOnInit() {
  }

}
